package com.huatai.manage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.query.RemoveQuery;
import com.huatai.manage.entity.TbTrialModelEntity;
import com.huatai.manage.service.TbTrialModelService;
import com.huatai.manage.utils.ComUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 模型表;(TbTrialModelManage)表控制层
 *
 * @author luoxc
 * @since 2023-03-14 14:13:39
 */
@RestController
@RequestMapping("model")
@Api(value = "模型管理", tags = "模型管理")
public class TbTrialModelController {

	@Autowired
	private TbTrialModelService tbTrialModelService;


	@ApiOperationSupport(order = 1, includeParameters = {
		"pageQuery.current",
		"pageQuery.size",
		"pageQuery.data.modelName",
		"pageQuery.data.modelType"
	})
	@PostMapping("pageList")
	@ApiOperation(value = "分页查询", notes = "分页查询")
	public R pageList(@RequestBody PageQuery<TbTrialModelEntity> pageQuery) {
		return R.data(this.tbTrialModelService.pageList(pageQuery));
	}

	@GetMapping("list")
	@ApiOperation(value = "查询所有数据", notes = "查询所有数据")
	public R list() {
		return R.data(this.tbTrialModelService.list());
	}


	@PostMapping("getByModelId")
	@ApiOperation(value = "模型id查询单条数据", notes = "模型id查询单条数据")
	public R getOne(@ApiParam(name = "modelId",value = "模型id", required = true) @RequestParam("modelId") String modelId) {
		return R.data(this.tbTrialModelService.getByModelId(modelId));
	}

	@PostMapping("insert")
	@ApiOperation(value = "新增数据", notes = "新增数据")
	public R insert(@RequestBody @Valid TbTrialModelEntity tbTrialModelEntity) {
		return R.status(this.tbTrialModelService.save(tbTrialModelEntity.setModelId(ComUtil.getUUID())));
	}

	@PostMapping("update")
	@ApiOperation(value = "修改数据", notes = "修改数据")
	public R update(@RequestBody @Valid TbTrialModelEntity tbTrialModelEntity) {
		return R.status(this.tbTrialModelService.update(tbTrialModelEntity));
	}

	@PostMapping("removes")
	@ApiOperation(value = "批量删除数据", notes = "批量删除数据")
	public R removes(@RequestBody RemoveQuery remove) {
		return R.status(this.tbTrialModelService.removes(remove.getIds()));
	}
}

